package com.lyf.core.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lyf.core.dao.LogDao;
import com.lyf.core.log.aspect.InfoLog;
import com.lyf.core.pojo.model.PageModel;
import com.lyf.core.service.LogService;

@Service
public class LogServiceImpl implements LogService{


	Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private LogDao logDao;
	  
	 
	public void insertLog(InfoLog log){
		 
		logDao.insert(log);
		logger.info(log);
		
	}
	
	  
	 
	@Override
	public PageModel<InfoLog> logPage(Date start, Date end, Integer uid,int page,int row) {
		
		PageModel<InfoLog> model = new PageModel<>();
		model.setPage(page);
		model.setRow(row);
		
		
		int cnt = logDao.selectDetailsCnt(start, end, uid);
		if(cnt < 1) {
			model.setTotal(0);
			return model ;
		}
		
		List<InfoLog> logs = logDao.selectDetailsModel(start, end, uid, page, row);
		model.setRows(logs);
		model.setTotal(cnt);
		
		
		return model;
	}


	@Override
	public List<InfoLog> findDetails(Date start, Date end, Integer uid) {
		// TODO Auto-generated method stub
		return logDao.selectDetails(start, end, uid);
	}
	
	 
	
}
